package com.ruoyi.wechat.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wechat.domain.Communication;
import com.ruoyi.wechat.service.ICommunicationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 营地交流Controller
 * 
 * @author ruoyi
 * @date 2024-12-25
 */
@RestController
@RequestMapping("/camp/communication")
public class CommunicationController extends BaseController
{
    @Autowired
    private ICommunicationService communicationService;

    /**
     * 查询营地交流列表
     */
    @PreAuthorize("@ss.hasPermi('camp:communication:list')")
    @GetMapping("/list")
    public TableDataInfo list(Communication communication)
    {
        startPage();
        List<Communication> list = communicationService.selectCommunicationList(communication);
        return getDataTable(list);
    }

    /**
     * 导出营地交流列表
     */
    @PreAuthorize("@ss.hasPermi('camp:communication:export')")
    @Log(title = "营地交流", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Communication communication)
    {
        List<Communication> list = communicationService.selectCommunicationList(communication);
        ExcelUtil<Communication> util = new ExcelUtil<Communication>(Communication.class);
        util.exportExcel(response, list, "营地交流数据");
    }

    /**
     * 获取营地交流详细信息
     */
    @PreAuthorize("@ss.hasPermi('camp:communication:query')")
    @GetMapping(value = "/{communicationId}")
    public AjaxResult getInfo(@PathVariable("communicationId") String communicationId)
    {
        return success(communicationService.selectCommunicationByCommunicationId(communicationId));
    }

    /**
     * 新增营地交流
     */
    @PreAuthorize("@ss.hasPermi('camp:communication:add')")
    @Log(title = "营地交流", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Communication communication)
    {
        return toAjax(communicationService.insertCommunication(communication));
    }

    /**
     * 修改营地交流
     */
    @PreAuthorize("@ss.hasPermi('camp:communication:edit')")
    @Log(title = "营地交流", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Communication communication)
    {
        return toAjax(communicationService.updateCommunication(communication));
    }

    /**
     * 删除营地交流
     */
    @PreAuthorize("@ss.hasPermi('camp:communication:remove')")
    @Log(title = "营地交流", businessType = BusinessType.DELETE)
	@DeleteMapping("/{communicationIds}")
    public AjaxResult remove(@PathVariable String[] communicationIds)
    {
        return toAjax(communicationService.deleteCommunicationByCommunicationIds(communicationIds));
    }
}
